import { ApiProperty } from "@nestjs/swagger";
import { $Enums, User } from "@prisma/client";
import { Transform } from "class-transformer";
import { IsEnum, IsNotEmpty, IsString, Matches, MinLength } from "class-validator";

export class CreateUserDto implements Pick<User, "channel" | "username" | "password"> {
    @Transform(({ value }) => value.trim())
    @Matches(/^[a-zA-Z0-9_]+$/, { message: "用户名只能包含字母、数字、下划线" })
    @IsString()
    @IsNotEmpty({ message: "用户名不能为空" })
    @MinLength(1, { message: "用户名至少1个字符" })
    @ApiProperty({
        description: "登录用户名，用户名只能包含字母、数字、下划线",
        example: "JohnDoe",
        required: true
    })
    username: string;

    @IsString()
    @IsNotEmpty({ message: "密码不能为空" })
    @MinLength(6, { message: "密码至少6个字符" })
    @ApiProperty({
        description: "密码",
        example: "password123",
        required: true
    })
    password: string;

    @IsEnum($Enums.Channel)
    @IsNotEmpty({ message: "渠道不能为空" })
    @ApiProperty({
        description: "渠道",
        example: `"wechatMiniProgram" | "wechatOfficialAccount" | "mobileH5" | "pc" | "iosApp" | "androidApp" |`,
        required: true
    })
    channel: $Enums.Channel;
}
